package com.taotao.cart.service;
import java.io.IOException;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.ClientProtocolException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.cart.bean.User;
import com.taotao.common.service.ApiService;

@Service
public class UserService {
	
	@Autowired
	private ApiService apiService;
	/**
	 * 调用sso系统接口
	 * 根据token获取用户信息
	 * @param token
	 * @return
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public User queryUserByToken(String token) throws ClientProtocolException, IOException {
		User user = null;
		String url = "http://sso.taotao.com/service/user/query/" + token;
		String jsonUser = this.apiService.doGet(url);
		if(StringUtils.isNotEmpty(jsonUser)){
			user = PropertiesService.MAPPER.readValue(jsonUser, User.class);
		}
		return user;
	}

	
}